package com.java_foundation.huawei.Test_16;

import java.util.*;

/**
 * @program: java_foundation
 * @description:
 * @author: xiongbangwen <Email>xiongbangwen@163.com</Email>
 * @create: 2020-08-07 21:10
 **/
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String strArray[] = str.split(" ");
        int a1 = Integer.parseInt(strArray[0]);
        int a2 = Integer.parseInt(strArray[1]);
        int result = 0;
        List<Integer> xList = new ArrayList<Integer>();
        List<Integer> yList = new ArrayList<Integer>();
        while (a1 > 0 && sc.hasNext()) {
            String params = sc.nextLine();
            String paramsArray[] = params.split(" ");
            int b1 = Integer.parseInt(paramsArray[0]);
            int b2 = Integer.parseInt(paramsArray[1]);
            xList.add(b1);
            yList.add(b2);
            a1--;
        }
        for (int i = xList.size()-1; i > 0; i--) {
            result = result + (xList.get(i) - xList.get(i - 1));
        }
        result = result + (a2 - xList.get(xList.size() - 1));
        System.out.println(result);
    }
}
